package cn.com.roy.thread.t6_2.singleton_2_3;

public class MyObject {
    private static MyObject myObject;

    private MyObject() {
    }

    //同步代码块效率一样底下
    public static MyObject getInstance() {
        try {
            if (myObject == null) {
                Thread.sleep(3000);
                //部分代码上锁，仍然无法解决线程安全问题
                synchronized (MyObject.class) {
                    myObject = new MyObject();
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return myObject;
    }
}
